<template>
  <div>
    <!--文创&#45;&#45;文创商品&#45;&#45;详情-->
    <content-header title="商品详情"></content-header>
    <div class="header xui-fc xui-margin-top-lg">
      <share :title="title" style="position:absolute;right:0"></share>
      <img-zoom :src="pic" width="320" height="306" :bigsrc="pic" :configs="configs" class="xui-fl"></img-zoom>
      <!-- <img-box :imgSrc="pic" width="320" height="306" class="xui-fl"></img-box> -->
      <div class="xui-fl xui-margin-left-md right">
        <h3>{{title}}</h3>
        <p class="xui-margin-vertical-sm">类型:
          <span>{{rtype}}</span>
        </p>
        <a v-if="shopAddress" :href="shopAddress" class="buy-btn" target="_blank">购买链接</a>
        <ul class="img-list">
          <li v-for="(item, index) in imgUrls" :key="index" class="xui-margin-right-xs" @mouseover="changeSrc(index)">
            <img-box :imgSrc="item" width="60" height="60"></img-box>
          </li>
        </ul>
      </div>
    </div>
    <div class="info xui-margin-top-md">
      <el-tabs type="border-card">
        <el-tab-pane label="详细介绍">
          <p class="xui-margin-bottom-lg bodyFont" ref="bodyFont" v-html="content" :class="{bodyHeight:isActive}">

          </p>
          <div class="all-text" @click="contentToggle()">
            <span>{{btnText}}</span>
            <i :class="{'el-icon-caret-top': isActive, 'el-icon-caret-bottom': !isActive}"></i>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
  import ContentHeader from "@/components/widge/content-header";
  import ImgBox from "@/components/widge/img-box";
  import {
    getCultureProdDetail,
    addBrowseNum
  } from "@/api/detail";
  import imgZoom from 'vue2.0-zoom'
  import defaultImg from "@/assets/images/default.png";
  import share from "@/components/widge/share";

  export default {
    components: {
      ImgBox,
      ContentHeader,
      share,
      imgZoom
    },
    data() {
      return {
        configs: {
          width: 320,
          height: 306,
          maskWidth: 160,
          maskHeight: 153,
          maskColor: '#D3AF68',
          maskOpacity: 0.1
        },
        title: "",
        rtype: "",
        shopAddress: "",
        pic: defaultImg,
        isActive: false,
        curHeight: 0,
        bodyHeight: 999999999999,
        btnText: "显示全部",
        imgUrls: [defaultImg],
        content: "暂无内容"
      };
    },
    methods: {
      contentToggle() {
        this.curHeight = this.$refs.bodyFont.offsetHeight;
        if (this.curHeight < this.bodyHeight) {
          this.isActive = !this.isActive;
          this.btnText = this.isActive === true ? "收起" : "显示全部";
        } else {
          this.btnText = "显示全部";
        }
      },
      changeSrc(index) {
        this.pic = this.imgUrls[index];
      },
      getDetail(id) {
        getCultureProdDetail(id).then(res => {
          this.title = res.data.title;
          this.rtype = res.data.rtype;
          this.imgUrls = res.data.imgUrls;
          this.pic = this.imgUrls[0];
          this.content = res.data.content;
          let addr = res.data.url.trim().toLowerCase();
          if (!addr) return false;
          if (addr.substring(0, 4) == "http") this.shopAddress = addr;
          else this.shopAddress = "http://" + addr;
        });
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.getDetail(this.$route.params.id);
        addBrowseNum(this.$route.params.id, "2");
      });
    }
  };

</script>
<style>
  #_magnifier_layer {
    margin-left: 10px
  }

</style>


<style lang="less" scoped>
  .bodyHeight {
    height: auto !important;
  }

  .bodyFont {
    height: 68px;
    overflow: hidden;
    max-height: 100%;
  }

  .info {
    .all-text {
      width: 75px;
      margin: 0 auto;
      cursor:pointer span {
        font-size: 14px;
        color: #dbad23;
      }
      i {
        color: #bf9c51;
      }
    }
  }

  .img-box {
    border: 1px solid #eeeeee;
  }

  .img-list {
    position: absolute;
    bottom: 0;
    height: 62px;
    li {
      cursor: pointer;
      display: inline-block;
      border: 2px solid #fff;
    }
    li:hover {
      border: 2px solid #dcad23;
    }
  }

  .header {
    position: relative;
    .right {
      h3 {
        color: #bf9b51;
        font-weight: normal;
      }
      p {
        background: url("../../../assets/images/list/dot.png") no-repeat 0 center;
        padding-left: 20px;
        color: #747474;
        font-size: 14px;
      }
      .el-button {
        background: #dbad23;
        border: 1px solid #dbad23;
        color: #fff;
        padding: 10px 32px;
      }
    }
  }

  .buy-btn {
    background-color: #dbad23;
    display: inline-block;
    color: #fff;
    text-align: center;
    font-size: 16px;
    padding: 6px 18px;
    border-radius: 4px;
    transition: background-color 0.2s;
  }

  .buy-btn:hover {
    background-color: #dbad23 - #111;
  }

</style>
